﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
using System.Data;
using System.Data.OleDb;

namespace DAO
{
    public class LoaiDiaDiemDAO
    {
        public static List<LoaiDiaDiemDTO> LayDanhSach()
        {
            List<LoaiDiaDiemDTO> lstLoaiDiaDiem = null;
            try
            {
                OleDbConnection cnn = BoKetNoiCSDL.KetNoi();
                OleDbCommand cmd = new OleDbCommand("SELECT * FROM LOAI_DIA_DIEM", cnn);
                try
                {
                    OleDbDataReader rd = cmd.ExecuteReader();
                    lstLoaiDiaDiem = new List<LoaiDiaDiemDTO>();
                    while (rd.Read())
                    {
                        LoaiDiaDiemDTO loaiDiaDiem = new LoaiDiaDiemDTO();
                        loaiDiaDiem.MaLoaiDiaDiem = (int)rd["MaLoaiDiaDiem"];
                        loaiDiaDiem.TenLoaiDiaDiem = (string)rd["TenLoaiDiaDiem"];

                        lstLoaiDiaDiem.Add(loaiDiaDiem);
                    }
                }
                catch (System.Exception ex)
                {
                    if (cnn.State == ConnectionState.Open)
                    {
                        cnn.Close();
                    }
                    throw ex;
                }
            }
            catch (System.Exception ex)
            {
                throw ex;
            }

            return lstLoaiDiaDiem;
        }
    }
}
